from rest_framework import serializers, status
from .models import *
from rest_framework.response import Response


class DepartmentSerSon(serializers.ModelSerializer):
    class Meta:
        model = Department
        fields = ("id", 'name')

class DepartmentSer(serializers.ModelSerializer):
    child = DepartmentSerSon(many=True)

    class Meta:
        model = Department
        fields = ("id", 'name', 'child')

class DepartSonSer(serializers.ModelSerializer):
    def get_fields(self):
        child = super(DepartSonSer, self).get_fields()
        child['child'] = DepartSonSer(many=True,read_only=True)
        return child
    class Meta:
         model = Department
         fields = ['id', 'name', 'child']


class TusersSerializer(serializers.ModelSerializer):
    # 定义序列化器字段
    class Meta:
        model = Tusers  # 假设 Department 是您的模型
        fields = '__all__'  # 或者指定需要序列化的字段


class DepartmentSer(serializers.ModelSerializer):
    child = DepartmentSerSon(many=True)

    class Meta:
        model = Department
        fields = ("id", 'name', 'child')


class PatientSer(serializers.ModelSerializer):
    idCard = serializers.SerializerMethodField()

    def get_idCard(self, obj):
        idCard = obj.code
        return idCard

    class Meta:
        model = Patient
        fields = ("id", "name", 'idCard')


class OrdersSer(serializers.ModelSerializer):
    class Meta:
        model = Orders
        fields = "__all__"


class PatientDoctorList(serializers.ModelSerializer):
    class Meta:
        model = PatientDoctor
        fields = "__all__"
